package{
	
	import flash.display.*;
	import com.greensock.*;
	import com.greensock.events.*;
	import com.greensock.loading.*;
	import com.greensock.easing.*;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import com.reintroducing.events.CustomEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.net.FileReference;
	import flash.utils.ByteArray;
	import flash.net.URLVariables;
	
	public class Initializer extends MovieClip{
		
		private var myProgressBar:MovieClip;
		private var loader:SWFLoader;
		private var params;
		
		public function Initializer():void 
		{ 
			stage.showDefaultContextMenu = false;
			stage.align=StageAlign.TOP;
			stage.scaleMode = StageScaleMode.NO_SCALE;
			
			loadMovie("intro.swf"); 
			//loadMovie("http://www.jadroagentbar.com/assets/swf/intro.swf"); 
		}	
		
		function loadMovie(name:String) {
			
			//initialize loader
			this.loader = new SWFLoader(name, {
				name: "loadedSWF",
				x: 0, 
				y: 0, 
				onInit: initHandler, 
				onProgress: progressHandler
			});
			
			//set progress bar
			myProgressBar= new loader_mc();
			/*myProgressBar.x = stage.stageWidth / 2;
			myProgressBar.y = stage.stageHeight / 2;*/
			
			myProgressBar.x = 723;
			myProgressBar.y = 285;
			addChild(myProgressBar);
			
			//begin loading
			loader.load();
			
		}
		
		function progressHandler(event:LoaderEvent):void
		{
			//round percentage -> display from 0 - 100%
			var prc = Math.round(event.target.progress * 100);
			myProgressBar.loading_app_mc.text = "loading "+prc+"%";
			
		}
		
		function initHandler(event:LoaderEvent):void
		{
			//Fadeout loader -> Fadein loader content
			TweenLite.to(myProgressBar, 1, {alpha: 0, ease: Sine.easeOut, onComplete:showContent });		
		}
		
		function showContent() 
		{
			
			// Display loaded content
			TweenLite.from(loader.content, 1.5, { alpha: 0, ease: Sine.easeOut } );
			addChild(loader.content);
			
		}
		
		function errorHandler(event:LoaderEvent):void
		{
			trace("error occured with " + event.target + ": " + event.text);
		}
		
	}
}